home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4827 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: nntp.cs.ubc.ca!bcsystems!sashome
  2. Newsgroups: comp.lang.c
  3. Subject: Suggestions welcome
  4. Message-ID: <1996Feb6.225454.7550@venus.gov.bc.ca>
  5. From: sasmith@bcsc02.gov.bc.ca (Steve Smith)
  6. Date: Wed, 07 Feb 96 06:56:34 GMT
  7. Organization: BC Systems Corporation
  8. Nntp-Posting-Host: vicsd211.dial.gov.bc.ca
  9. X-Newsreader: News Xpress 2.0 Beta #0
  10.  
  11. I am writing a C++ Console application to extract information from a 
  12. proprietary database file.
  13.  
  14. In order to interpret some of the data in a record, I need to read in
  15. a flat file which contains lists of values for certain variables. A 
  16. sample would be:
  17.  
  18. ++$ CITYNAMES
  19. VICTORIA
  20. VANCOUVER
  21. EDMONTON
  22. CALGARY
  23. TORONTO
  24. MONTREAL
  25. QUEBEC
  26. ++$ END
  27.  
  28. The city name field in the database record is a single byte, where 01 = 
  29. VICTORIA, 02 = VANCOUVER etc.
  30.  
  31. There are a number of such lists in the flat file, several have > 200 entries.
  32. I want to read these lists in to my program, and be able to access them
  33. using an array index (such as CityName[i]).
  34.  
  35. I don't know how many elements will be in the array from one run to the
  36. next, so I can't (and wouldn't want to) statically allocate an array.
  37.  
  38. The only way I can think of to accomplish this, is the read through the 
  39. flat file twice. 
  40.  
  41. On the first pass, count the number of elements required for each 
  42. unique list. Once I know how many elements are required I can dynamically 
  43. allocate an array of pointers to string for each list.
  44.  
  45. On the second pass through the file, I can allocate storage for each string,
  46. copy it into memory and initialize the char* array with the pointer.
  47.  
  48. If anyone has any other suggestions on how I could accomplish this, I would be 
  49. interested in hearing from them (either e-mail or post).
  50.  
  51. Thanks in advance
  52.  
  53. Steve Smith
  54. sasmith@orca.osg.gov.bc.ca
  55.  
  56. them.
  57. each list 
  58.